// 计数器
var PageCounter = {
    id: "PageCounter", //页面id
    menu: "i18n.lan.menu.io", //所属菜单(一级菜单名)
    title: "i18n.lan.menu.PageCounter", //标题（二级菜单名）
    icon: "icon-me-counter", //图标
    refreshBtnCmd: "IOS_DUMPS", //刷新按钮指令
    saveBtn: true, //保存按钮
    content: "test", //页面内容
    el: [ //控件
        {
            elname:"button",
            text:i18n.lan.PageCounter.resetCounter,
            endRow:true,
            attrs:{
                onclick:"PageCounter_ResetCounter()",
                style:"margin-left:900px;padding:0 10px;",
                title:i18n.lan.PageCounter.selectRowOrAll,
            }
        },
        {
            elname: "datagrid",
            rowCount: Device.getNodesCount("di"), //必选,行数
            data: {
                width:"100%",
                frozenColumns: [
                    [{
                        field: "index",
                        title: i18n.lan.common.index,
                        width: "40px",
                        align: "center"
                    }, ]
                ],
                columns: [
                    [{
                            field: "value",
                            dumpKey: "COUNTER<n>STATE",
                            dumpParamIndex: 1,
                            width: 80,
                        }, 
                        {
                            field: "name",
                            editor: Easyui.editor.textbox,
                            dumpKey: "COUNTER<n>NAME",
                            dumpParamIndex: 0,
                            transcode: "true",
                            cmdKey: "COUNTER<n>NAME",
                            otherFields: "unit", //其它的参数
                            width: 100,
                        },
                        {
                            field: "unit",
                            editor: Easyui.editor.textbox,
                            dumpKey: "COUNTER<n>NAME",
                            dumpParamIndex: 1,
                            transcode: "true",
                            id: "counter<n>unit",
                            width: 80,
                        },
                        //下面的参数都是使用的DIN的                
                        {
                            field: "adjValue",
                            editor: Easyui.editor.numberbox4,
                            dumpKey: "DIN<n>NODE_RANGE1",
                            dumpParamIndex: 3,
                            cmdKey: "DIN<n>ADJ",
                            width: 80,
                        },
                        {
                            field: "scaleValue",
                            editor: Easyui.editor.numberbox4,
                            dumpKey: "DIN<n>NODE_RANGE1",
                            dumpParamIndex: 4,
                            cmdKey: "DIN<n>SCALE",
                            width: 80,
                        },
                        {
                            field: "alarmHighVal",
                            editor: Easyui.editor.numberbox4,
                            dumpKey: "DIN<n>NODE_RANGE1",
                            dumpParamIndex: 0,
                            cmdKey: "DIN<n>HIGH",
                            width: 80,
                        },
                        {
                            field: "resetValue",
                            editor: Easyui.editor.numberbox4,
                            dumpKey: "DIN<n>NODE_CT",
                            dumpParamIndex: 1,
                            cmdKey: "DIN<n>RESET",
                            width: 80,
                        },
                        {
                            field: "stepValue",
                            editor: Easyui.editor.numberbox4,
                            dumpKey: "DIN<n>NODE_RANGE2",
                            dumpParamIndex: 3,
                            cmdKey: "DIN<n>STEP",
                            width: 80,
                        },
                        {
                            field: "uploadTimer",
                            editor: Easyui.editor.numberbox,
                            dumpKey: "DIN<n>NODE_IOTTO",
                            dumpParamIndex: 0,
                            cmdKey: "DIN<n>IOTTO",
                            width: 100,
                        },
                        // {
                        //     field: "logTimer",
                        //     dumpKey: "DIN<n>NODE_IOTTO",
                        //     dumpParamIndex: 1,
                        //     id:"din<n>logto",
                        // },
                        {
                            field: "counter",
                            formatter:Easyui.formatter.checkbox,
                            editor: Easyui.editor.checkbox,
                            dumpKey: "DIN<n>NODE_CT",
                            dumpParamIndex: 0,
                            cmdKey: "DIN<n>COUNTEREN",
                            width: 70,
                            align:"center",
                        },
                        {
                            field: "smsAlarm",
                            formatter:Easyui.formatter.checkbox,
                            editor: Easyui.editor.checkbox,
                            dumpKey: "DIN<n>NODE_PARAM",
                            dumpParamIndex: 0,
                            cmdKey: "DIN<n>SMSEN",
                            width: 70,
                            align:"center",
                        },
                        {
                            field: "recoverSms",
                            formatter:Easyui.formatter.checkbox,
                            editor: Easyui.editor.checkbox,
                            dumpKey: "DIN<n>NODE_PARAM",
                            dumpParamIndex: 2,
                            cmdKey: "DIN<n>SMSREN",
                            width: 70,
                            align:"center",
                        },
                        {//断开短信
                            field: "disconnSms",
                            formatter:Easyui.formatter.checkbox,
                            editor: Easyui.editor.checkbox,
                            dumpKey: "DIN<n>NODE_PARAM",
                            dumpParamIndex: 3,
                            cmdKey: "DIN<n>SMSDISCONNEN",
                            width: 70,
                            align:"center",
                        },
                        {
                            field: "soundAlarm",
                            formatter:Easyui.formatter.checkbox,
                            editor: Easyui.editor.checkbox,
                            dumpKey: "DIN<n>NODE_PARAM",
                            dumpParamIndex: 1,
                            cmdKey: "DIN<n>SOUNDEN",
                            width: 70,
                            align:"center",
                        },
                    ]
                ],
            }
        },
    ],
}
CmdPage.add(PageCounter); //添加到页面管理

//复位计数器值
function PageCounter_ResetCounter(){
    let row = $("#PageCounter_dg").datagrid("getSelected");
    let cmdKey = "COUNTERRESET";
    if(row){
        sendCmd(cmdKey+row.index);
    }else{
        let cmds = [];
        for(let i=0;i<Device.getNodesCount("di");i++){
            cmds.push(cmdKey+i);
        }
        sendCmds(cmds);
    }
}
